package labox.innovation.gameserver.datatables;

import java.io.File;
import java.sql.Connection;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config;
import labox.innovation.config.Server;

import javolution.util.FastList;
import javolution.util.FastMap;
import javolution.util.FastSet;
import labox.innovation.gameserver.model.FuzePracticeSkillLearn;
import labox.innovation.gameserver.model.L2EnchantSkillLearn;
import labox.innovation.gameserver.model.L2PledgeSkillLearn;
import labox.innovation.gameserver.model.L2Skill;
import labox.innovation.gameserver.model.L2SkillLearn;
import labox.innovation.gameserver.model.L2EnchantSkillLearn.EnchantSkillDetail;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.model.base.ClassId;
import labox.innovation.gameserver.skills.DoucmentParseLearnSkill;
import labox.innovation.gameserver.templates.StatsSet;

/**
 * 技能学习表
 * version1 2010.1.6 
 * 修改了 职业 或 种族的技能学习组织 不包括其他特殊技能。如国王等.
 * 
 */
public class SkillTreeTable {
	public static final int NORMAL_ENCHANT_COST_MULTIPLIER = 1;

	public static final int SAFE_ENCHANT_COST_MULTIPLIER = 3;

	public static final int NORMAL_ENCHANT_BOOK = 6622;

	public static final int SAFE_ENCHANT_BOOK = 9627;

	public static final int CHANGE_ENCHANT_BOOK = 9626;

	public static final int UNTRAIN_ENCHANT_BOOK = 9625;
	
	public static final List<Integer> _learnSkillLvl = new FastList<Integer>();
	
	//职业 或 种族的最大id
	//10000以后的id 用做特殊技能分类用途
	public static final int MAX_CLASS_ID = 10000;

	private static Logger _log = LoggerFactory.getLogger(SkillTreeTable.class.getName());
	
	/**
	 * 保存所有技能的学习条件, 为 获取指定id和等级的技能快速获得学习条件而设
	 * key 是 技能等级 + 技能id的哈希函数
	 */
	private Map< Integer, L2SkillLearn> _allSkillLearn = new FastMap<Integer, L2SkillLearn>(); 

	//保存每个职业的技能学习树
	private Map<ClassId, Map< Integer, L2SkillLearn> > _skillTrees;
	
	//技能学习等级书
	//主key 为classId
	// Second key 为 技能最低学习等级
	// 主要为 发送角色 技能信息给 客户端，  预分类， 加快速度
	private Map<ClassId, Map< Integer, Set<Integer> > > _skillLvlTrees = new FastMap<ClassId, Map<Integer,Set<Integer>>>();
	
	//保存所有仙魔位的 技能学习树
	//第一个key 为仙魔位称号id
	//第二个key 为仙魔位修为id
//	private Map<Integer, List<L2SkillLearn > > _practiceSkillTrees = new FastMap<Integer, List<L2SkillLearn>>();
	
	/**
	 *  主key, 职业id
	 *  second Key 仙魔位
	 */
	Map<Integer, Map<Integer, List<L2SkillLearn> > > _practiceSkillTrees = new FastMap<Integer, Map<Integer,List<L2SkillLearn>>>();
	
	/**
	 * 主key, 职业id
	 * second Key 仙魔位
	 * 仙魔位技能的id。 只有技能id
	 * 主要为 发送角色 技能信息给 客户端，  预分类， 加快速度
	 */
	private Map<ClassId, Map< Integer, Set<Integer> > > _practiceSkillIds = new FastMap<ClassId, Map<Integer,Set<Integer>>>();


	public static SkillTreeTable getInstance() 
	{
		return SingletonHolder._instance;
	}
	
	
//	/**
//	 *  获得指定仙魔位称号的 所有技能
//	 * @param practiceId : 仙魔位称号Id
//	 * @return   List<L2SkillLearn>    key为仙魔位的修为id
//	 */
//	public List<L2SkillLearn> getPracticeSkills( int practiceId )
//	{
//		return _practiceSkillTrees.get( practiceId );
//	}
	
	/**
	 * 添加 技能学习数据到表中
	 */
	protected void addIntoAllSkillLerans( int key, L2SkillLearn learn )
	{
		_allSkillLearn.put( key, learn );
	}
	
	/**
	 * 获得技能的 学习条件 
	 * @param skillId
	 * @param skillLvl
	 */
	public L2SkillLearn getSkillLearn(int skillId, int skillLvl )
	{
		return _allSkillLearn.get( SkillTable.getSkillHashCode( skillId, skillLvl ) );
	}
	
	/**
	 * 获得指定仙魔位称号 和 修为的 所有技能
	 * classId : 职业id
	 *  practiceId : 仙魔位称号Id
	 *  thoughtId  : 仙魔位的修为id   现已不存在修为
	 */
	public List<L2SkillLearn> getPracticeSkills( int classId, int practiceId  )
	{
		
		Map<Integer, List<L2SkillLearn> > temp = getPracticeSkillForClassId(classId);
		if( temp == null )
		{
			return null;
		}
		
		List<L2SkillLearn> tempList = temp.get( practiceId );
		
		return tempList;
		
	}
	
	/**
	 * 获得指定技能id仙魔位的学习条件
	 * @param classId
	 * @param practiceId
	 * @param thoughtId   现已不存在修为
	 * @param skillId
	 * @return
	 */
	public L2SkillLearn getPracticeSkill( int classId, int practiceId, int skillId )
	{

		List<L2SkillLearn> slList = getPracticeSkills( classId, practiceId );
		if( slList == null )
		{
			return null;
		}
		
		for( L2SkillLearn sl : slList )
		{
			if( sl.getId() == skillId )
			{
				return sl;
			}
		}
		
		_log.warn("没有找到技能id为: " + skillId + " 的仙魔位技能学习条件" , Config.SERVER_ID );
		return null;
		
	}
	


	/**
	 * Return the minimum level needed to have this Expertise.<BR><BR>
	 *
	 * @param grade The grade level searched
	 */
	/***
	 * 学习 grade级技能的 最低人物等级
	 */
	public int getExpertiseLevel(int grade) {
		if (grade <= 0)
			return 0;

		// since expertise comes at same level for all classes we use paladin for now
		// 对任何职业来说 学习同样 等级的技能，需要的人物等级都是一样的。所有这使用的是骑士的
		Map<Integer, L2SkillLearn> learnMap = getSkillTrees().get(ClassId.fighter);

		int skillHashCode = SkillTable.getSkillHashCode(239, grade);
		if (learnMap.containsKey(skillHashCode)) {
			return learnMap.get(skillHashCode).getMinLevel();
		}

		_log.warn("Expertise not found for grade " +  grade, Config.SERVER_ID);
		return 0;
	}

	/**
	 * Each class receives new skill on certain levels, this methods allow the retrieval of the minimun character level
	 * of given class required to learn a given skill
	 * @param skillId The iD of the skill
	 * @param classID The classId of the character
	 * @param skillLvl The SkillLvl
	 * @return The min level
	 */
	/***
	 * 返回指定职业(ClassID)学习某个等级的技能，需要的最低人物等级
	 */
	public int getMinSkillLevel(int skillId, ClassId classId, int skillLvl) {
		Map<Integer, L2SkillLearn> map = getSkillTrees().get(classId);

		int skillHashCode = SkillTable.getSkillHashCode(skillId, skillLvl);

		if (map.containsKey(skillHashCode)) {
			return map.get(skillHashCode).getMinLevel();
		}

		return 0;
	}

	/***
	 * 返回学习某个等级技能 需要最低的人物等级
	 * 
	 * @param skillId
	 * @param skillLvl
	 * @return
	 */
	public int getMinSkillLevel(int skillId, int skillLvl) 
	{
		int skillHashCode = SkillTable.getSkillHashCode(skillId, skillLvl);


		if (_allSkillLearn.containsKey(skillHashCode)) {
			
			return _allSkillLearn.get(skillHashCode).getMinLevel();
		}

		return 0;
	}
	
	/**
	 * 根据 职业类型 和 技能id 返回技能的学习条件
	 * @param iSkillType
	 * @param iSkillID
	 * @return
	 */
	public L2SkillLearn getLearnSkillCon( int iSkillType, int iSkillID, int iSkillLevel )
	{
		//种族 或 职业 技能
		if( iSkillType < MAX_CLASS_ID )
		{
			Map<Integer, L2SkillLearn> parentMap = getSkillTrees().get( ClassId.getClassId(iSkillType) );
			
			if( parentMap != null )
			{
				
				return parentMap.get( SkillTable.getSkillHashCode( iSkillID, iSkillLevel ) );
				
			}// end if( parentMap != null )
			
		}
		
		return null;
		
	}// end
	
	
    public static void main(String args[])
    {
		Server.serverMode = Server.MODE_GAMESERVER;
		Config.load();
		
    	SkillTreeTable.getInstance();
    }

	/***
	 * 
	 * 保存了 各种可学的技能
	 * 所有的可学的技能 都来自模板配置
	 */
	private SkillTreeTable() {
		int count = 0;
		int count2 = 0;
		
		String [] str = Config.LEARN_SKILL_LVL != null ?Config.LEARN_SKILL_LVL.split(";") : null;
		if( str != null )
		{
			for( String t : str )
			{
				_learnSkillLvl.add( Integer.parseInt( t ) );
			}
			
			if( _log.isDebugEnabled() )
				_log.debug("可学的技能的等级范围: {" + Config.LEARN_SKILL_LVL + "}", Config.SERVER_ID);
		}

		try {

			//职业技能
			//解析xml
			try
			{
			    Map<Integer, L2SkillLearn> map;
//				int parentClassId;
				L2SkillLearn skillLearn;
				
				//职业技能配置文件
				File file = new File(Config.DATAPACK_ROOT, "data/Stats/Config/ClassIdLearnSkill.xml");
//				File file = new File("Test.xml");
				
				DoucmentParseLearnSkill dps = new DoucmentParseLearnSkill( file );
				dps.parse();
				
				//获得所有职业的技能
				Map<Integer, List<StatsSet>  > allSkill = dps.getAllSkill();
//				System.out.println("所有职业技能数:" + allSkill.size() );
				Iterator< Map.Entry< Integer, List<StatsSet> > > ssKey = allSkill.entrySet().iterator();
				while( ssKey.hasNext() )
				{
					Map.Entry< Integer, List<StatsSet> > ss = ssKey.next();
					
					map = new FastMap<Integer, L2SkillLearn>();
					List< StatsSet > skillSet = ss.getValue();
					int iClassId = ss.getKey();
					
					int iSetSize = skillSet.size();
					for( int j = 0 ; j < iSetSize; j++  )
					{
						StatsSet set = skillSet.get( j );
						set.set("class_need", iClassId );
						int id = set.getInteger("id");
						int lvl = set.getInteger("lvl");
						skillLearn = new L2SkillLearn( set );
						addClassIDLvlSkill(ClassId.getClassId(iClassId), skillLearn);
						map.put(SkillTable.getSkillHashCode(id, lvl), skillLearn);
						L2Skill skill = SkillTable.getInstance().getInfo(id, lvl);
						if( skill != null )
							skill.getSkillDes(skillLearn);
						addIntoAllSkillLerans( SkillTable.getSkillHashCode(id, lvl), skillLearn );
						
					}// end for( int j = 0 ; j < iSetSize; j++  )
					
					//更新所有职业可学的技能表
					getSkillTrees().put(ClassId.getClassId(iClassId), map);
					
					count += map.size();
				
					if( _log.isDebugEnabled() )
						_log.debug("SkillTreeTable: skill tree for class {}  has  {} skills" , iClassId, map.size() );
					
				}// end while
				
//				for(Map.Entry< Integer, List<StatsSet> > ss:allSkill.entrySet() )
//				{
//					map = new FastMap<Integer, L2SkillLearn>();
//					List< StatsSet > skillSet = ss.getValue();
//					int iClassId = ss.getKey();
//					
//					int iSetSize = skillSet.size();
//					for( int j = 0 ; j < iSetSize; j++  )
//					{
//						StatsSet set = skillSet.get( j );
//						int id = set.getInteger("id");
//						int lvl = set.getInteger("lvl");
//						skillLearn = new L2SkillLearn( set );
//						addClassIDLvlSkill(ClassId.getClassId(iClassId), skillLearn);
//						map.put(SkillTable.getSkillHashCode(id, lvl), skillLearn);
//						
//					}// end for( int j = 0 ; j < iSetSize; j++  )
//					
//					//更新所有职业可学的技能表
//					getSkillTrees().put(ClassId.getClassId(iClassId), map);
//					
//					count += map.size();
//					_log.fine("SkillTreeTable: skill tree for class " + iClassId + " has " + map.size() + " skills");
//					
//				}// end for(Map.Entry<Integer, List<StatsSet>> ss:allSkill.entrySet())
				

			if( _log.isDebugEnabled() )
				_log.info("SkillTreeTable: Loaded {}  skills" ,count);
				_log.debug("职业技能加载了：{}" , count );
			
			}
			catch (Exception e)
			{
				_log.error( "Error while creating skill table ", Config.SERVER_ID, e);
			}

			//仙魔位 技能
			//解析xml
			try 
			{
//				_practiceSkillTrees = new FastMap<Integer,List<L2SkillLearn> >();
				
				List<L2SkillLearn> skillList;
				L2SkillLearn skillLearn;
				File file = new File(Config.DATAPACK_ROOT, "data/Stats/Config/PracticeLearnSkill.xml");
				DoucmentParseLearnSkill dps = new DoucmentParseLearnSkill( file );
				dps.parse();
				//获得所有仙魔位的技能
				Map<Integer, List<StatsSet>  > allSkill = dps.getAllSkill();
				
				Iterator< Map.Entry< Integer, List<StatsSet> > > ssKey = allSkill.entrySet().iterator();
				while( ssKey.hasNext() )
				{
					Map.Entry< Integer, List<StatsSet> > ss = ssKey.next();
					
					int practiceId = ss.getKey();  //仙魔位称号
					List< StatsSet > skillSet = ss.getValue();
					skillList = new FastList<L2SkillLearn>();
					
					
					int iSetSize = skillSet.size();
					for( int j = 0 ; j < iSetSize; j++  )
					{
						StatsSet set = skillSet.get( j );
						
						int id = set.getInteger("id");
						int lvl = set.getInteger("lvl");
						
						skillLearn = new FuzePracticeSkillLearn( set );
						addPracticeSkill( practiceId , skillLearn);
						L2Skill skill = SkillTable.getInstance().getInfo(id, lvl);
						if( skill != null )
							skill.getSkillDes(skillLearn);
						addIntoAllSkillLerans( SkillTable.getSkillHashCode(id, lvl), skillLearn );
						
					}// end for( int j = 0 ; j < iSetSize; j++  )
					
					//更新所有职业可学的技能表
//					_practiceSkillTrees.put( practiceId, skillList );
					
					count2 += skillList.size();
					if( _log.isDebugEnabled() )
						_log.debug("SkillTreeTable: skill tree for class {}  has {} skills" , practiceId , skillList.size());
					
				}// end while
				
//				for(Map.Entry< Integer, List<StatsSet> > ss:allSkill.entrySet() )
//				{
//		
//					int practiceId = ss.getKey();  //仙魔位称号
//					List< StatsSet > skillSet = ss.getValue();
//					skillList = new FastList<L2SkillLearn>();
//					
//					
//					int iSetSize = skillSet.size();
//					for( int j = 0 ; j < iSetSize; j++  )
//					{
//						StatsSet set = skillSet.get( j );
//		
//						skillLearn = new FuzePracticeSkillLearn( set );
//						addPracticeSkill( practiceId , skillLearn);
////						skillList.add( skillLearn );
//						
//					}// end for( int j = 0 ; j < iSetSize; j++  )
//					
//					//更新所有职业可学的技能表
////					_practiceSkillTrees.put( practiceId, skillList );
//					
//					count2 += skillList.size();
//					_log.fine("SkillTreeTable: skill tree for class " + practiceId + " has " + skillList.size() + " skills");
//					
//				}// end for(Map.Entry<Integer, List<StatsSet>> ss:allSkill.entrySet())
				
				if( _log.isDebugEnabled() )
					_log.debug("SkillTreeTable: Loaded {} skills.仙魔位技能" , count2);
				if( _log.isDebugEnabled() )
					_log.debug("职业技能加载了：{}" , count2);
				
			} 
			catch 
			(Exception e) 
			{
				_log.error("Error while creating practice skill table ", Config.SERVER_ID, e);
			}
			
		} 
		catch (Exception e) 
		{
			_log.error( "Error while skill tables ",Config.SERVER_ID, e);
		} 
		finally 
		{

		}
		
	}
	
	/**
	 *  增加技能的  最低学习等级树
	 * @param ClassId
	 * @param skillLearn
	 */
	protected void addClassIDLvlSkill( ClassId classId, L2SkillLearn skillLearn )
	{
		//如果技能最低学习等级限制 不满足条件 或 技能表里不存在这个技能
		if( !isInThisSkillLvl( skillLearn.getMinLevel() ) || SkillTable.getInstance().getInfo( skillLearn.getId(), 1) == null  ) 
		{
			if( _log.isDebugEnabled() && SkillTable.getInstance().getInfo( skillLearn.getId(), 1) == null )
			{
				_log.debug( skillLearn.getName() + " 技能id为 ：{} 等级为: {} 的技能不存在， 或 是不可学的技能等级", skillLearn.getId(), skillLearn.getMinLevel() );
			}
			
			return;
		}
		
		Map< Integer, Set<Integer> > skillMap = _skillLvlTrees.get( classId );
		if( skillMap == null )
		{
			skillMap = new FastMap<Integer, Set<Integer> >();
		}
		
		Set<Integer> skillList = skillMap.get( skillLearn.getMinLevel() );
		if( skillList == null )
		{
			skillList = new FastSet<Integer>();
		}
		
		skillList.add( skillLearn.getId() );
		skillMap.put( skillLearn.getMinLevel(), skillList );
		_skillLvlTrees.put( classId, skillMap );
		
	}
	
	/**
	 * 是否包含这个最低学习等级
	 * @param lvl
	 * @return
	 */
	protected boolean isInThisSkillLvl( int lvl )
	{
		return _learnSkillLvl.contains( lvl );
	}
	
	public List<Integer> getSkillLvls()
	{
		return _learnSkillLvl;
	}
	
	/**
	 * 
	 * @param practiceId
	 * @param skillLearn
	 */
	protected void addPracticeSkill( int practiceId, L2SkillLearn skillLearn )
	{
		int classId = ( (FuzePracticeSkillLearn)skillLearn ).getClassId();
		if( classId < 0 || SkillTable.getInstance().getInfo( skillLearn.getId(), 1) == null )
		{
			if( _log.isDebugEnabled() )
				_log.debug("技能id为 :{} 技能不存在", skillLearn.getId() );
			return;
		}
		//仙魔位技能树
		Map<Integer, List<L2SkillLearn> > praSks = _practiceSkillTrees.get( classId );
		//仙魔位技能ids
		Map< Integer, Set<Integer> > pskllIds = _practiceSkillIds.get( ClassId.getClassId(classId) );
		if( praSks == null )
		{
			praSks = new FastMap<Integer, List<L2SkillLearn>>();
		}
		if( pskllIds == null )
		{
			pskllIds = new FastMap<Integer, Set<Integer>>();
		}
		
		//仙魔位技能
		List<L2SkillLearn> skills = praSks.get( practiceId );
		//仙魔位技能Ids
		Set<Integer> skllIds = pskllIds.get( practiceId );
		if( skills == null )
		{
			skills = new FastList<L2SkillLearn>();
		}
		if( skllIds == null )
		{
			skllIds = new FastSet<Integer>();
		}
		
		
		
		skills.add( skillLearn );
		praSks.put( practiceId, skills );
		_practiceSkillTrees.put(classId, praSks);
		
		skllIds.add( skillLearn.getId() );
		pskllIds.put( practiceId, skllIds );
		_practiceSkillIds.put( ClassId.getClassId(classId), pskllIds );
		
	}
	
	
	/**
	 *  获得 某职业  最低学习等级 可以学的所有技能
	 * @param classId
	 * @param lvl
	 * @return
	 */
	public Set<Integer> getClassIdLvl( ClassId classId, int lvl )
	{
		Map< Integer, Set<Integer> > skillMap = _skillLvlTrees.get( classId );
		
		if( skillMap == null )
		{
			return null;
		}
		
		return skillMap.get( lvl );
	}
	
	/**
	 *  获得 某职业的所有技能id
	 *  @param classId
	 *  @return
	 */
	public Map< Integer, Set<Integer> > getClassIdLvl( ClassId classId )
	{
//		System.out.println("获职业技能id:" + classId );
		return _skillLvlTrees.get( classId );
	}
	
	/**
	 *  获得 某个职业的仙魔位技能
	 * @param classId
	 * @return
	 */
	public Map<Integer, List<L2SkillLearn> > getPracticeSkillForClassId( int classId )
	{
		return _practiceSkillTrees.get( classId );
	}
	
	/**
	 *  获得 某职业仙魔位技能的 所有技能id
	 * @param classId
	 * @return
	 */
	public Map<Integer, Set<Integer> > getPracticeSkillIdForClassId( int classId )
	{
		
		return _practiceSkillIds.get( ClassId.values()[classId] );

	}

	/***
	 * 返回 所有职业可学技能表
	 * @return
	 */
	private  Map<ClassId, Map<Integer, L2SkillLearn>> getSkillTrees() {
		if (_skillTrees == null)
			_skillTrees = new FastMap<ClassId, Map<Integer, L2SkillLearn>>();

		return _skillTrees;
	}
	
	/**
	 *  获得 所有职业的技能
	 * @return
	 */
	public Map<ClassId, Map<Integer, L2SkillLearn>> getAllClassIDSkills()
	{
		return _skillTrees;
	}
	
	/**
	 *  获得所有仙魔位技能
	 * @return
	 */
	public Map<Integer, Map<Integer, List<L2SkillLearn> > > getPracticeSkills()
	{
		return _practiceSkillTrees;
	}
	

	/***
	 * 获得某个职业角色可学的技能
	 * 职业技能
	 * @param cha
	 * @param classId
	 * @return
	 */
	public L2SkillLearn[] getAvailableSkills(FuzePcInstance cha, ClassId classId) {
		List<L2SkillLearn> result = new FastList<L2SkillLearn>();
		Map<Integer, L2SkillLearn> templist = getSkillTrees().get(classId);
		Collection<L2SkillLearn> skills = null;
		
		if( templist != null )
			skills = getSkillTrees().get(classId).values();
		

		if (skills == null) {
			// the skilltree for this class is undefined, so we give an empty list
			if( _log.isDebugEnabled() )
				_log.debug("Skilltree for class {}  is not defined !" , classId );
			return new L2SkillLearn[0];
		}

		L2Skill[] oldSkills = cha.getAllSkills();

		for (L2SkillLearn temp : skills) {
			//如果当前技能最低学习等级 < 人物等级
			if (temp.getMinLevel() <= cha.getLevel()) {
				boolean knownSkill = false;

				for (int j = 0; j < oldSkills.length && !knownSkill; j++) {
					if (oldSkills[j].getId() == temp.getId()) {
						knownSkill = true;

						if (oldSkills[j].getLevel() == temp.getLevel() - 1) {
							// this is the next level of a skill that we know
							result.add(temp);
						}
					}
				}// end for (int j = 0; j < oldSkills.length && !knownSkill; j++)

				if (!knownSkill && temp.getLevel() == 1) {
					// this is a new skill
					result.add(temp);
				}
			}// end if (temp.getMinLevel() <= cha.getLevel())

		}// end 

		return result.toArray(new L2SkillLearn[result.size()]);

	}// end getAvailableSkills


	/**
	 * Returns all allowed skills for a given class.
	 * @param classId
	 * @return all allowed skills for a given class.
	 * 获得某个职业 所有的技能
	 */
	public Collection<L2SkillLearn> getAllowedSkills(ClassId classId) {
		Map<Integer, L2SkillLearn> temp = getSkillTrees().get(classId);
		if( temp != null )
			return temp.values();
		else 
			return null;
	}

	public int getMinLevelForNewSkill(FuzePcInstance cha, ClassId classId) {
		int minLevel = 0;
		Collection<L2SkillLearn> skills = getSkillTrees().get(classId).values();

		if (skills == null) {
			// the skilltree for this class is undefined, so we give an empty list
			if( _log.isDebugEnabled() )
				_log.debug("Skilltree for class {} is not defined !" , classId );
			return minLevel;
		}

		for (L2SkillLearn temp : skills) {
			//技能最低学习等级 > 人物等级，且 sp话费不为0
//			if (temp.getMinLevel() > cha.getLevel() && temp.getSpCost() != 0)
//				if (minLevel == 0 || temp.getMinLevel() < minLevel)
//					minLevel = temp.getMinLevel();
		}

		return minLevel;
	}

	public int getMinLevelForNewSkill(FuzePcInstance cha) {
		int minLevel = 0;
		List<L2SkillLearn> skills = new FastList<L2SkillLearn>();

		if (skills == null) {
			// the skilltree for this class is undefined, so we give an empty list
			if( _log.isDebugEnabled() )
				_log.debug("SkillTree for fishing is not defined !");
			return minLevel;
		}

		for (L2SkillLearn s : skills) {
			if (s.getMinLevel() > cha.getLevel())
				if (minLevel == 0 || s.getMinLevel() < minLevel)
					minLevel = s.getMinLevel();
		}

		return minLevel;
	}


	@SuppressWarnings("synthetic-access")
	private static class SingletonHolder {
		protected static final SkillTreeTable _instance = new SkillTreeTable();
	}
	
}
